<?php
class AdminModel extends Model{
	public $table='admin';
	public function __construct(){
		parent::__construct();

	}
	public function checkAdmin($data){
		if(empty($data['username'])){
			$this->error='用户名不能为空';
			return false;
		}
		if(empty($data['password'])){
			$this->error='密码不能为空';
			return false;
		}
		$admin=$this->where("username='{$data['username']}'")->find();
		if(empty($admin)){
			$this->error='用户名不存在';
			return false;
		}
		if(md5($data['password'])!=$admin['password']){
			$this->error='密码错误';
			return false;
		}
		$_SESSION['aid']=$admin['aid'];
		$_SESSION['username']=$admin['username'];
		return true;
	}

	//修改密码
	public function change($data){
		// return 
		$password=md5($data['password']);
		$res=$this->where("aid={$_GET['aid']} and password='$password'")->find();
		if(empty($res)){
			$this->error='密码错误请重试';
			return false;
		}else{
			return true;
		}

	}
	//确认新密码
	public function newPwd($data){
		$data['password']=md5($data['password']);
		return $this->where("aid={$data['aid']}")->update($data);
	}
}
?>